package com.zxx.pattern.observerPattern.observer1;

/**
 * @author zxx on 2021/3/9
 */
public class TestObserver1 {

    public static void main(String[] args) {
        //创建主题（被观察者）
        Subject subject = new NewsOffice();

        //创建观察者
        Observer observer1 = new Person1();
        Observer observer2 = new Person2();

        //为观察者注册主题
        subject.addObserver(observer1);
        subject.addObserver(observer2);

        //主题发送消息
        subject.setThing("今日头条");
        System.out.println();
        subject.setThing("hahahhahah哈哈哈哈哈");

        System.out.println("----------------------");
        subject.removeObserver(observer1);
        subject.setThing("发送取消订阅");

    }

}
